﻿/************************************************
*
* Copyright(c) ZeeGuo.com
*
* CLR : 4.0.30319.296
*
* FileName : Entity4399ComicBook.cs
*
* Author : Kurodo
*
* CreatTime : 2013/7/23 17:00:08
*           
*************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComicSpider.Model;

namespace ComicSite
{
    public class Entity4399ComicBook : EntityComicBook
    {
        protected override string GetBookName(string context)
        {
            return DataMatch.RegexsValue(context, "voltitle    = '(\\w{1,30})_", 1);
            //Regex regName = new Regex("g_comic_name = \"\\w{1,50}\";");
            //return regName.Matches(context)[0].Value;
        }

        protected override string GetChapterName(string context)
        {
            return DataMatch.RegexsValue(context, "shorttitle  = '(\\w{1,10})';", 1);
            //Regex regChapter = new Regex("g_chapter_name = \"(\\w{1,50})\";");
            //return regChapter.Matches(context)[0].Value;
        }

        protected override int GetPageCount(string context)
        {
            return int.Parse(DataMatch.RegexsValue(context, "var pic_count = (\\d{1,3}),", 1));
            //Regex regPage = new Regex("g_max_pic_count = \\d{1,3}\";");
            //return int.Parse(regPage.Matches(context)[0].Value);
        }

        public override List<string> GenerateComicPages(string context)
        {
            this.UrlPrefix = DataMatch.RegexsValue(context, "picdir  = '(http://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?)';", 1);
            this.Comic_Pages = new List<string>();
            string url = string.Empty;
            for (int i = 0; i < this.Comic_PageCount; i++)
            {
                if (i < 9)
                {
                    url = string.Format("{0}00{1}.jpg", this.UrlPrefix, i + 1);
                }
                else if (i < 99)
                {
                    url = string.Format("{0}0{1}.jpg", this.UrlPrefix, i + 1);
                }
                else
                {
                    url = string.Format("{0}{1}.jpg", this.UrlPrefix, i + 1);
                }

                this.Comic_Pages.Add(url);
            }

            return this.Comic_Pages;
        }
    }
}
